import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { DelDataButton, ExecuteButton, TestDetailsButton, ModDataButton } from '../Common/options'
import { ProjectList } from '../Common/Conversion'

export const LabReboundHammer = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    const { hostname } = window.location
    let data = {
        pageSize: 10,
        get: API_LIST()[`get${url}OC`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        params: { pageIndex: 1 },
        columns: [
            commonTableList.uuid,
            { ...commonTableList.SearchSort, selectType: 'LabReboundHammer' },
            {
                ...commonTableList.projectUuid,
                valueEnum: await ProjectList(),
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
                hideInSearch: !hostname.includes('jszx'),
            },
            {
                ...commonTableList.organizationUuid,
                valueEnum: ClientData.organization,
                hideInModify: true,
            },
            {
                dataIndex: 'componentNumber',
                title: '构件编号',
                valueType: 'input',
                width: 200,
            },
            {
                dataIndex: 'componentName',
                title: '构件名称',
                valueType: 'input',
                width: 200,
            },
            {
                dataIndex: 'detectionTime',
                title: '检测时间',
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'designGrade',
                title: '砼设计强度',
                valueType: 'input',
                width: 120,
            },
            {
                dataIndex: 'componentStrength',
                title: '构件强度',
                valueType: 'input',
                hideInSearch: true,
                width: 100,
            },
            {
                dataIndex: 'carbonationDepthdata',
                title: '碳化深度',
                valueType: 'input',
                hideInSearch: true,
                width: 120,
            },
            // ! 合并
            {
                dataIndex: 'testSurface',
                title: '测试状态',
                valueType: 'input',
                hideInSearch: true,
                hideInModify: true,
                width: 150,
                render: (_, e) => {
                    const { testSurface, sideIsdry, sideRough } = e
                    const testSurfaceList = { 0: '表面', 1: '侧面', 2: '底面' }
                    const sideIsdryList = { 0: '干燥', 1: '湿润' }
                    const sideRoughList = { 0: '光滑', 1: '粗糙' }
                    return (
                        <div>
                            {testSurfaceList[testSurface]},{sideIsdryList[sideIsdry]},{sideRoughList[sideRough]}
                        </div>
                    )
                },
            },
            {
                dataIndex: 'testAngle',
                title: '测试角度',
                valueType: 'input',
                hideInSearch: true,
                width: 100,
            },
            { ...commonTableList.isEnabled, rules: true, hideInSearch: false },
            {
                dataIndex: 'equipmentNumber',
                title: '设备编号',
                valueType: 'input',
                width: 250,
            },
            {
                dataIndex: 'equipmentName',
                title: '设备名称',
                valueType: 'input',
                width: 400,
            },
            commonTableList.BeginStatDate,
            commonTableList.EndStatDate,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 300,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, isEnabled } = record
                    return [
                        <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" url={url} data={record} />,
                        <TestDetailsButton
                            key="test"
                            title="试验详情"
                            OptionsEvent={OptionsEvent}
                            data={{
                                type: 'LabReboundHammer',
                                title: '回弹仪试验详情',
                                data: { uuid },
                            }}
                        />,
                        Permission.findIndex(v => v.uuid === 'bbae189e-0efa-4bbf-a7f0-106888c43a56') !== -1 &&
                            isEnabled !== 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="启用"
                                    url="posLabReboundHammerSetIsEnabled"
                                    path={[uuid, 1]}
                                    tips="数据启用成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === 'bbae189e-0efa-4bbf-a7f0-106888c43a56') !== -1 &&
                            isEnabled === 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="禁用"
                                    danger={true}
                                    url="posLabReboundHammerSetIsEnabled"
                                    path={[uuid, 0]}
                                    tips="数据禁用成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === '23a74a02-dd32-40c8-a6d7-ed166ebd544c') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
